//
//  ViewController.m
//  DLClassCategoryDemo
//
//  Created by David Lee on 13-10-31.
//  Copyright (c) 2013年 DL. All rights reserved.
//

#import "ViewController.h"
#import "SafeMethods.h"

@interface ViewController ()
@property (retain, nonatomic) IBOutlet UIView *flexibleView;

@end

@implementation ViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handelPan:)];
    [self.flexibleView addGestureRecognizer:pan];
    [pan release];
}

// 改变flexibleView的大小
-(void)handelPan:(UIPanGestureRecognizer*)gestureRecognizer
{
    CGPoint curPoint = [gestureRecognizer locationInView:self.view];
    int minx = CGRectGetMinX(self.flexibleView.frame);
    int miny = CGRectGetMinY(self.flexibleView.frame);
    if (curPoint.x > minx && curPoint.y > miny) {
        [self.flexibleView setWidth:curPoint.x - minx];
        [self.flexibleView setHeightAssociated:curPoint.y - miny];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)linearLayout:(id)sender {
    CGFloat height = [self.view linearLayout];
    NSLog(@"Height:%.f", height);
}

- (void)dealloc {
    [_flexibleView release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setFlexibleView:nil];
    [super viewDidUnload];
}
@end
